import {Card, Row, Col, List, Typography, Space, Tag, Table} from "antd";
import Base from "@/pages/Province/SubjectDetail/components/Base";
import {CaretDownFilled, CaretUpFilled, FileWordOutlined} from '@ant-design/icons'
import Pie from './components/Pie'
import type {ColumnsType} from 'antd/es/table';
import {nanoid} from "@ant-design/pro-components";
import {history} from "@@/core/history";
import {useEffect, useState} from "react";
import {Detail01Evaluation, Detail01Found, Detail01Influence, Detail01Upload} from "@/services/Province/Dashboard";

interface DataType {
  key: string; // table 唯一
  yr: number; // 年度
  total_fund: number; // 总经费数
  ctr_budg_fund: number; // 中央预算经费
  ctr_receive_fund: number; // 中央实际到账经费
  ctr_expend_fund: number; // 中央实支出经费
  lcl_budg_fund: number; // 地方预算经费
  lcl_receive_fund: number; // 地方实际到账经费
  lcl_expend_fund: number; // 地方实际支出经费
  self_budg_fund: number; // 自筹预算经费
  self_receive_fund: number; // 自筹实际经费
  self_expend_fund: number; // 自筹实际支出经费
  other_budg_fund: number; // 其他预算经费
  other_receive_fund: number; // 其他实际到账经费
  other_expend_fund: number; // 其他实际支出经费
}

const columns: ColumnsType<DataType> = [
  {
    title: '年度',
    dataIndex: 'yr',
    key: 'yr',
  },
  {
    title: '经费总数(万元)',
    dataIndex: 'total_fund',
    key: 'total_fund',
  },
  {
    title: '中央预算经费',
    dataIndex: 'ctr_budg_fund',
    key: 'ctr_budg_fund',
  },
  {
    title: '中央实际到账经费',
    key: 'ctr_receive_fund',
    dataIndex: 'ctr_receive_fund',
  },
  {
    title: '中央实际支出经费',
    key: 'ctr_expend_fund',
    dataIndex: 'ctr_expend_fund',
  },
  {
    title: '地方预算经费',
    dataIndex: 'lcl_budg_fund',
    key: 'lcl_budg_fund',
  },
  {
    title: '地方实际到账经费',
    key: 'lcl_receive_fund',
    dataIndex: 'lcl_receive_fund',
  },
  {
    title: '地方实际支出经费',
    key: 'lcl_expend_fund',
    dataIndex: 'lcl_expend_fund',
  },
  {
    title: '学科自筹预算经费',
    dataIndex: 'self_budg_fund',
    key: 'self_budg_fund',
  },
  {
    title: '学科自筹实际到账经费',
    key: 'self_receive_fund',
    dataIndex: 'self_receive_fund',
  },
  {
    title: '学科自筹实际支出经费',
    key: 'self_expend_fund',
    dataIndex: 'self_expend_fund',
  },
];


export default (props) => {

  const urlArr = history.location.pathname.split('/')
  const school = urlArr[urlArr.length - 1]
  const subject = urlArr[urlArr.length - 2]
  const schoolSubject = school + '-' + subject
  const [evaluationData, setEvaluationData] = useState([])
  const [rankData, setRankData] = useState([])
  const [findData, setFindData] = useState([])
  const [uploadData, setuploadData] = useState([])
  const [reload, setReload] = useState(false)
  useEffect(() => {
    Detail01Evaluation({subject: schoolSubject}).then(res => {
      if (res.status === 0) {
        setEvaluationData([
          {
            title: '第四轮学科评估',
            rank: res.data[0],
          },
          {
            title: <span>第五轮学科评估<Typography.Text strong>(预估)</Typography.Text></span>,
            rank: res.data[1],
          },
        ])
      }
    })
    Detail01Influence({subject: schoolSubject}).then(res => {
      if (res.status === 0) {
        setRankData(res.data)
      }
    })
    Detail01Found({subject: schoolSubject}).then(res => {
      if (res.status === 0) {
        setFindData(res.data)
      }
    })
    // Detail01Upload({subject: schoolSubject}).then(res => {
    //   if (res.status === 0) {
    //     setuploadData(res.data)
    //   }
    // })
  }, [reload])


  return <Base props={props}>
    <Row gutter={[24, 24]}>
      {/*<Col span={24}>*/}
      {/*  <Card title="学科进展写实">*/}
      {/*    <List*/}
      {/*      bordered*/}
      {/*      dataSource={uploadData}*/}
      {/*      renderItem={item => (*/}
      {/*        <List.Item>*/}
      {/*          <div>*/}
      {/*            <Typography.Title level={4}> {item.title} </Typography.Title>*/}
      {/*            <p className="good-content-size">{item.content}</p>*/}
      {/*          </div>*/}
      {/*        </List.Item>*/}
      {/*      )}*/}
      {/*    />*/}
      {/*  </Card>*/}
      {/*</Col>*/}
      <Col span={24}>
        <Card title="学科评估情况">
          <List
            grid={{gutter: 16, column: 4}}
            dataSource={evaluationData}
            renderItem={item => (
              <List.Item>
                <Card title={item.title}>
                  <span style={{fontSize: 16}}>学科评估：<Typography.Text strong>{item.rank}</Typography.Text></span>
                </Card>
              </List.Item>
            )}
          />
        </Card>
      </Col>
      <Col span={24}>
        <Card title="学科影响力情况">
          <List
            grid={{gutter: 16, column: 4}}
            dataSource={rankData}
            renderItem={item => (
              <List.Item>
                <Card title={item.title + '-' + item.year}>
                  <span style={{fontSize: 16}}>
                    <Space align="center">
                      <Typography.Text>学科排名：</Typography.Text>
                    <Typography.Text strong>{item.rank}</Typography.Text>
                      {/*{item.ave - item.rank > 0 && <Tag color="red"><CaretUpFilled />较平均值{item.ave}高{item.ave-item.rank}位</Tag>}*/}
                      {/*{item.ave - item.rank == 0 && <Tag color="blue">与平均值持平</Tag>}*/}
                      {/*{item.ave - item.rank < 0 && <Tag color="green"><CaretDownFilled/>较平均值{item.ave}低{item.rank-item.ave}位</Tag>}*/}
                    </Space>
                  </span>
                </Card>
              </List.Item>
            )}
          />
          <Typography.Text strong>
            注：平均值为本平台已填报学科统计出的均值。
          </Typography.Text>
        </Card>
      </Col>
      <Col span={24}>
        <Card title="本学科建设经费数">
          <Row gutter={[24, 24]}>
            <Col span={24}>
              <Table columns={columns} dataSource={findData}/>
            </Col>
          </Row>
          {/*<Row gutter={24}>*/}
          {/*  <Col span={8}>*/}
          {/*    <Pie name="预算经费占比(万元)"*/}
          {/*         data={[{value: 100, name: "中央预算经费"}, {value: 200, name: "地方预算经费"}, {value: 100, name: "自筹预算经费"}]}*/}
          {/*         radius="65%"*/}
          {/*         width="100%"*/}
          {/*    />*/}
          {/*  </Col>*/}
          {/*  <Col span={8}>*/}
          {/*    <Pie name="实际到账占比(万元)"*/}
          {/*         data={[{value: 100, name: "中央预算经费"}, {value: 200, name: "地方预算经费"}, {value: 100, name: "自筹预算经费"}]}*/}
          {/*         radius="65%"*/}
          {/*         width="100%"*/}
          {/*         height=""*/}
          {/*    />*/}
          {/*  </Col>*/}
          {/*  <Col span={8}>*/}
          {/*    <Pie name="实际支出占比(万元)"*/}
          {/*         data={[{value: 100, name: "中央预算经费"}, {value: 200, name: "地方预算经费"}, {value: 100, name: "自筹预算经费"}]}*/}
          {/*         radius="65%"*/}
          {/*         width="100%"*/}
          {/*         height=""*/}
          {/*    />*/}
          {/*  </Col>*/}
          {/*</Row>*/}
        </Card>
      </Col>
    </Row>
  </Base>
}
